##zestaw5 #zadanie1 library(faraway) summary(data) ?star data=star m1=lm(temp~light,star) summary(m1) library(car) boxCox(m1,lambda = seq(-2, 25)) m2=lm(temp^(14)~light,star) summary(m2) #wykresy plot(star$temp~star$light) par(mfrow=c(3,2)) plot(m1,1) plot(m1,2) plot(m1,3) plot(m1,4) plot(m1,5) plot(m1,6) par(mfrow=c(3,2)) plot(m2,1) plot(m2,2) plot(m2,3) plot(m2,4) plot(m2,5) plot(m2,6) ###porównanie modeli m1 i m2 data r1=0 r2=0 for( j in (1:length(data))) { training=data[-j,] test=data[j,] m1=lm(temp~light,training) m2=lm(temp^(14)~light,training) r1=r1+abs((predict(m1,test) )- test$temp ) r2=r2+abs((predict(m2,test) )^(1/14)- test$temp ) } rmse1=r1/length(data) rmse2=r2/length(data) rmse1 rmse2 ##Wygrywa model 2, bo ma mniejsze rmse. Ale jest trudniejszy do interpretacji par(mfrow=c(1,1)) rstudent(m1) plot(abs(rstudent(m1))) which(abs(rstudent(m1))>2) ###gwiazdy podejrzane: 11,20,30,34 #nie możemy je usunąć!